package com.auth.client.util;

import com.auth.client.config.context.AppContext;
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTCreator;

import java.util.Date;

/**
 * 生成token
 *
 * @author: mhSui 2020/07/01
 */
public class TokenUtil {

    private static final int expire = 15 * 24 * 60 * 60 * 1000;

    /**
     * 生成token.
     * @param id 登录的用户
     * @return 生成的token
     */
    public static String createToken(String id,String phone) {
        JWTCreator.Builder builder = JWT.create().withIssuedAt(new Date())
                .withExpiresAt(new Date(System.currentTimeMillis() + expire))
                .withSubject(id).withIssuer("u")
                .withClaim("mobile",phone);
        return builder.sign(AppContext.get().getAlgorithm());
    }
}
